#include <string>
#include "strs.h"
using namespace std;
long long strlen(char *str)
{
    return sizeof(str) / sizeof(char);
}


char *converter(string str)
{
    char *res = new char[str.size() + 1];
    strcpy(res, str.c_str());
    return res;
}

char *iton(long long a)
{
    if (a == 0)
        return "0";
    if (a == 1)
        return "1";
    if (a == 2)
        return "2";
    if (a == 3)
        return "3";
    if (a == 4)
        return "4";
    if (a == 5)
        return "5";
    if (a == 6)
        return "6";
    if (a == 7)
        return "7";
    if (a == 8)
        return "8";
    if (a == 9)
        return "9";
    return "0";
}

int ntoi(char a,  bool &err)
{
    if (a == '0')
        return 0;
    else
    if (a == '1')
        return 1;
    else
    if (a == '2')
        return 2;
    else
    if (a == '3')
        return 3;
    else
    if (a == '4')
        return 4;
    else
    if (a == '5')
        return 5;
    else
    if (a == '6')
        return 6;
    else
    if (a == '7')
        return 7;
    else
    if (a == '8')
        return 8;
    else
    if (a == '9')
        return 9;
    else
    {
        err = true;
        return -1;
    }
}

string inttostr(long long val)
{
    string str = "";
    if (val == 0)
        return "0";
    long long value = val;
    if (val  < 0)
    {
        value = -val;
        str = inttostr(value);
        str = "-" + str;
        return str;
    }
    while (value > 0)
    {
        str = iton(value % 10) + str;
        value /= 10;
    }
    return str;
}


string uinttostr(unsigned long long val)
{
    string str = "";
    long long value;
    if (val == 0)
        return "0";
    while (value > 0)
    {
        str = iton(value % 10) + str;
        value /= 10;
    }
    return str;
}


int strtoint(string str,  bool &err)
{
    int pw =1;
    int res = 0;
    int tc = 0;
    if (str[0] == '-')
        tc++;
    for (int i = str.length(); i > tc; i--)
    {
        int rp = ntoi(str[i - 1], err);
        if (err)
        {
            return -1;
        }
        res +=  rp * pw;
        pw *= 10;
    }
    if (tc)
        res *= -1;
    return res;
}

long strtolong(string str,  bool &err)
{
    long pw =1;
    long res = 0;
    int tc = 0;
    if (str[0] == '-')
        tc++;
    for (int i = str.length(); i > tc; i--)
    {
        int rp = ntoi(str[i - 1], err);
        if (err)
        {
            return -1;
        }
        res +=  rp * pw;
        pw *= 10;
    }
    if (tc)
        res *= -1;
    return res;
}

long long strtolonglong(string str, bool &err)
{
    long long pw = 1;
    long long res = 0;
    int tc = 0;
    if (str[0] == '-')
        tc++;
    for (int i = str.length(); i > tc; i--)
    {
        int rp = ntoi(str[i - 1], err);
        if (err)
        {
            return -1;
        }
        res +=  rp * pw;
        pw *= 10;
    }
    if (tc)
        res *= -1;
    return res;
}

unsigned int strtouint(string str,  bool &err)
{
    int pw = 1;
    int res = 0;
    int tc = 0;
    if (str[0] == '-')
        tc++;
    for (int i = str.length(); i > tc; i--)
    {
        int rp = ntoi(str[i - 1], err);
        if (err)
        {
            return -1;
        }
        res +=  rp * pw;
        pw *= 10;
    }
    if (tc)
        res *= -1;
    return res;
}

unsigned long strtoulong(string str,  bool &err)
{
    long pw =1;
    long res = 0;
    int tc = 0;
    if (str[0] == '-')
        tc++;
    for (int i = str.length(); i > tc; i--)
    {
        int rp = ntoi(str[i - 1], err);
        if (err)
        {
            return -1;
        }
        res +=  rp * pw;
        pw *= 10;
    }
    if (tc)
        res *= -1;
    return res;
}

unsigned long long strtouulonglong(string str, bool &err)
{
    long long pw = 1;
    long long res = 0;
    int tc = 0;
    if (str[0] == '-')
        tc++;
    for (int i = str.length(); i > tc; i--)
    {
        int rp = ntoi(str[i - 1], err);
        if (err)
        {
            return -1;
        }
        res +=  rp * pw;
        pw *= 10;
    }
    if (tc)
        res *= -1;
    return res;
}

